package main.java.study.step01;

import java.util.Arrays;

/**
 * @author liuwenxiu
 * @Description: 二维数组
 * @date 2022-7-12 10:52
 */
public class TwiDimensionalArray {
    
    

    public static void main(String[] args) {
        // 二维数组的创建
        int[][] arr = new int[3][4];
        print(arr);
        
        // 二维数组的赋值
        // 1.通过下标一一赋值
        arr[0][0] = 1;
        arr[1][1] = 2;
        arr[2][2] = 3;
        print(arr);
        
        // 2.在定义二维数组的同时进行赋值
        int[][] arr2 = new int[][]{{1,3,5},{2,4,6},{7,8,9,10}};
        // 简写如下
        int[][] arr3 = {{1,3,5},{2,4,6},{7,8,9,10}};
        print(arr2);
        print(arr3);
        
        // 3.一行一行地赋值
        int[][] arr4 = new int[2][3];
        arr4[0] = new int[]{1,2,3};
        arr4[1] = new int[]{3,4,5};
        print(arr4);
        
        // 4.通过for循环一一赋值
        int[][] arr5 = new int[2][3];
        for (int i = 0; i < arr5.length; i++) {
            for (int j = 0; j < arr5[i].length; j++) {
                arr5[i][j] = i + j;
            }
        }
        print(arr5);
    }
    
    
    private static void print(int[][] arr){
        for (int[] ints : arr) {
            for (int anInt : ints) {
                System.out.print(anInt + "\t");
            }
            System.out.println();
        }
        System.out.println("-----------------------");
    }
    
    
    private static void print1(int[][] arr){
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.println(arr[i][j]);
            }
        }
    }
    
    private static void print2(int[][] arrList){
        for (int[] arr : arrList) {
            for (int a : arr) {
                System.out.println(a);
            }
        }
        System.out.println(Arrays.deepToString(arrList));
    }
    
    
}
